package com.sq.partner.manager.controller;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sq.partner.manager.common.Constants;
import com.sq.partner.manager.common.DictCache;
import com.sq.partner.manager.dao.IGatewayTradCovDao;
import com.sq.partner.manager.mybatis.model.CoreProdInst;
import com.sq.partner.manager.mybatis.model.CoreProdPlan;
import com.sq.partner.manager.mybatis.model.DictDto;
import com.sq.partner.manager.mybatis.model.GatewayUser;
import com.sq.partner.manager.mybatis.model.RiskAlgMap;
import com.sq.partner.manager.mybatis.model.TradCalDef;
import com.sq.partner.manager.mybatis.model.TradCov;
import com.sq.partner.manager.mybatis.model.TradInsuPlan;
import com.sq.partner.manager.mybatis.model.TradItemCal;
import com.sq.partner.manager.mybatis.model.TradPlanBase;
import com.sq.partner.manager.mybatis.model.TradPlanCov;
import com.sq.partner.manager.mybatis.model.TradProdInst;
import com.sq.partner.manager.mybatis.model.TradProdPlan;
import com.sq.partner.manager.service.IGatewayProductService;
import com.sq.partner.manager.util.LogUtil;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.StrUtil;

/**
 * 
 * @author duguangwei
 * 产品定义 TradProdInst
 */
@Controller
@RequestMapping("/product")
public class ProductController {
	 private static Logger logger = LogUtil.getLog(ProductController.class);
	@Resource
	IGatewayProductService productService;
	@Resource
	IGatewayTradCovDao GatewayTradCovDao;
	/**
	 * 跳转产品列表页面
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/list")
	public String productDefinition(ModelMap model,HttpServletRequest request) throws Exception {
		
		return "product/list";
	}
	/**
	 * 跳转添加页面
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/add")
	public String add(ModelMap model,HttpServletRequest request) throws Exception {
		
		List<DictDto> agentTypeList = DictCache.getDict(Constants.DICT_AGENT_TYPE);
		model.put("agentTypeList", agentTypeList);
		return "product/add";
	}
	/**
	 * 
	 * @param model
	 * @param tradProdCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/edit")
	public String edit(ModelMap model,String tradProdCode) throws Exception {
		
		if(StrUtil.isEmpty(tradProdCode)){
			model.put("error", "操作错误");
			return "product/edit";
		}
		TradProdInst tradProdInst=new TradProdInst();
		tradProdInst.setTradProdCode(tradProdCode);
		tradProdInst=productService.queryTradProdInst(tradProdInst);
		
		List<DictDto> agentTypeList = DictCache.getDict(Constants.DICT_AGENT_TYPE);
		model.put("agentTypeList", agentTypeList);
		
		//加载编辑页面产品信息
		model.put("product",tradProdInst);
		return "product/edit";
	}
	/**
	 * 跳转险种页面
	 * @param model
	 * @param request
	 * @param tradProdCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/prodPlan")
	public String prodPlan(ModelMap model,HttpServletRequest request,String tradProdCode) throws Exception {
		TradProdInst prod = productService.queryTradProdInstById(tradProdCode);
		if(null==prod){
			throw new Exception("产品代码不存在");
		}
		model.put("tradProdCode", tradProdCode);
		model.put("tradProdDesc", prod.getTradProdDesc());
		model.put("poolType", prod.getPoolType());
		TradCalDef trad=new TradCalDef();
		trad.setState("01");
		trad.setNoCalDefId("0000000008");//不包含新意健险算法定义
		List<TradCalDef> tradCalDef=productService.queryTradCalDef(trad);
		model.put("tradCalDef", tradCalDef);
		return "product/insurance/add";
	}
	/**
	 * 查询产品列表
	 * @param size
	 * @param current
	 * @param tradProdCode
	 * @param tradProdDesc
	 * @param status
	 * @param startDate
	 * @param endDate
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryList")
	public @ResponseBody Page<TradProdInst> queryList(Integer size,Integer current,String tradProdCode,String tradProdDesc,String status,String startDate,String endDate) throws SQLException{
		Page<TradProdInst> page=new Page<TradProdInst>();
		page.setCurrent(current);
		page.setSize(size);
		TradProdInst tradProdInst=new TradProdInst();
		tradProdInst.setTradProdCode(tradProdCode);
		tradProdInst.setTradProdDesc(tradProdDesc);
		tradProdInst.setStatus(status);
		
		
		tradProdInst.setVstartDate(startDate);
		tradProdInst.setVendDate(endDate);
		page.setType(tradProdInst);
		return productService.queryPage(page);
	}
	/**
	 * 加载产品模板
	 * @param size
	 * @param current
	 * @param prodNme
	 * @param instCode
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/loadTemplet")
	public @ResponseBody Page<CoreProdInst> loadTemplet(Integer size,Integer current,String prodNme,String instCode) throws SQLException{
		
		Page<CoreProdInst> page=new Page<CoreProdInst>();
		page.setCurrent(current);
		page.setSize(size);
		//产品模板表
		CoreProdInst coreProdInst=new CoreProdInst();
		coreProdInst.setProdNme(prodNme);
		coreProdInst.setInstCode(instCode);
		page.setType(coreProdInst);
		return productService.queryProdInstPage(page);
	}
	/**
	 * 保存产品
	 * @param tradProdDesc
	 * @param tradAppType
	 * @param prodInstCode
	 * @param instant
	 * @param maxDelayDay
	 * @param maxDays
	 * @param minDays
	 * @param unitPp
	 * @param status
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/save")
	public @ResponseBody  Page<TradProdInst> saveTradProdInst(String tradProdDesc,String tradAppType,String prodInstCode,String instant,Long maxDelayDay,Long maxDays,Long minDays,Long unitPp,String prodType,String poolType,String poolRatio,String ageLimit,Integer minAge,Integer maxAge,String maxOccupLevel,String insuredNoLimit,Integer minInsuredNo,Long minDelayDay,String adjustStr,String agentType,String pppUnit) throws Exception{
		
		Page<TradProdInst> page =new Page<TradProdInst>();

		if(StrUtil.isEmpty(prodInstCode)){
			page.setMessage("产品模板代码不能为空");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(tradAppType)){
			page.setMessage("交易系统投保类型不能为空");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(prodType)){
			page.setMessage("产品类型不能为空");
			page.setResult("error");
			return page;
		}

		if(StrUtil.isEmpty(minDelayDay)){
			page.setMessage("最短延时起保天数不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("(0|[1-9][0-9]*)");  
	        Matcher matcher = pattern.matcher(minDelayDay.toString());
	        if(!matcher.matches()){
				page.setMessage("最短延时起保天数必须是不小于0的整数");
				page.setResult("error");
				return page;
	        }
		}
		if(StrUtil.isEmpty(maxDelayDay)){
			page.setMessage("最长延时起保天数不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("(0|[1-9][0-9]*)");  
	        Matcher matcher = pattern.matcher(maxDelayDay.toString());
	        if(!matcher.matches()){
				page.setMessage("最长延时起保天数必须是不小于0的整数");
				page.setResult("error");
				return page;
	        }else{
	        	if(maxDelayDay<minDelayDay){
					page.setMessage("最长延时起保天数不能小于最短延时起保天数");
					page.setResult("error");
					return page;
	        	}
	        }
		}
		
		if(StrUtil.isEmpty(minDays)){
			page.setMessage("最小保险期间不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("[1-9][0-9]*");  
	        Matcher matcher = pattern.matcher(minDays.toString());
	        if(!matcher.matches()){
				page.setMessage("最小保险期间必须是不小于1的整数");
				page.setResult("error");
				return page;
	        }
		}

		
		if(StrUtil.isEmpty(maxDays)){
			page.setMessage("最大保险期间不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("[1-9][0-9]*");  
	        Matcher matcher = pattern.matcher(maxDays.toString());
	        if(!matcher.matches()){
				page.setMessage("最大保险期间必须是不小于1的整数");
				page.setResult("error");
				return page;
	        }else{
	        	if(maxDays<minDays){
					page.setMessage("最大保险期间不能小于最小保险期间");
					page.setResult("error");
					return page;
	        	}
	        }
		}
		if(StrUtil.isEmpty(pppUnit)){
			page.setMessage("保险期间类型不能为空");
			page.setResult("error");
			return page;
		}
		BigDecimal fpoolRatio=null;
		if(StrUtil.isEmpty(poolType)){
			page.setMessage("共保选项不能为空");
			page.setResult("error");
			return page;
		}else{
			if("1".equals(poolType)){
				if(StrUtil.isEmpty(poolRatio)){
					page.setMessage("共保份额不能为空");
					page.setResult("error");
					return page;
				}else{
					Pattern pattern = Pattern.compile("[1-9][0-9]?|100");  
			        Matcher matcher = pattern.matcher(poolRatio.toString());
			        if(!matcher.matches()){
						page.setMessage("共保份额必须是1-100的有效整数");
						page.setResult("error");
						return page;
			        }
				}
					DecimalFormat df = new DecimalFormat("#.00");
					Double ratio = Double.parseDouble(poolRatio);
					if("0".equals(poolRatio)){
						fpoolRatio=new BigDecimal(df.format(Double.parseDouble("0")));
					}else{
						Double ratioPercent = ratio/100;
						fpoolRatio=new BigDecimal(df.format(ratioPercent));
					}
				}
		}
		if(StrUtil.isEmpty(instant)){
			page.setMessage("即时投保限制不能为空");
			page.setResult("error");
			return page;
		}

		/**
		 * 校验投保年龄限制不能为空，如果选择 ”是“，则必须输入最低、最高年龄，且最低年龄不大于最高年龄
		 * 如果是”否“，不输入最低、最高年龄
		 */
		if(StrUtil.isEmpty(ageLimit)){
			page.setMessage("请选择投保年龄限制");
			page.setResult("error");
			return page;
		}else{
			if("Y".equals(ageLimit)){
				if(null==minAge){
					page.setMessage("请输入最低投保年龄");
					page.setResult("error");
					return page;
				}else{
			        if(minAge>999||minAge<0){
						page.setMessage("最低年龄为0-999的有效整数");
						page.setResult("error");
						return page;
					}
				}
	
				if(null==maxAge){
					page.setMessage("请输入最高投保年龄");
					page.setResult("error");
					return page;
				}else{
					if(maxAge>999||maxAge<0){
						page.setMessage("最高年龄为0-999的有效整数");
						page.setResult("error");
						return page;
					}
				}
				
				if(minAge.intValue()>maxAge.intValue()){
					page.setMessage("最低投保年龄不能大于最高投保年龄");
					page.setResult("error");
					return page;
				}
			}
		}
		
		/**
		 * 校验最低投保人数限制不能为空，如果选择 ”是“，则必须最低投保人数
		 * 如果是”否“，不输入最低投保人数
		 */
		if(StrUtil.isEmpty(insuredNoLimit)){
			page.setMessage("请选择最低投保人数限制");
			page.setResult("error");
			return page;
		}else{
			if("Y".equals(insuredNoLimit)){
				if(null==minInsuredNo){
					page.setMessage("请输入最低投保人数");
					page.setResult("error");
					return page;
				}else{
					if(minInsuredNo>99999||minInsuredNo<0){
						page.setMessage("最低投保人数为0-99999的有效整数");
						page.setResult("error");
						return page;
					}
				}
			}
		}
		if(StrUtil.isEmpty(unitPp)){
			page.setMessage("最大份数不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("(0|[1-9][0-9]*)");  
	        Matcher matcher = pattern.matcher(unitPp.toString());
	        if(!matcher.matches()){
				page.setMessage("最大份数必须是不小于0的整数");
				page.setResult("error");
				return page;
	        }
		}

		/**
		 * 销售类型
		 */
		if(StrUtil.isEmpty(agentType)){
			page.setMessage("请选择销售类型");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(tradProdDesc)){
			page.setMessage("交易系统产品描述不能为空");
			page.setResult("error");
			return page;
		}
		TradProdInst tradProdInst=new TradProdInst();
		tradProdInst.setTradProdDesc(tradProdDesc);
		tradProdInst.setTradAppType(tradAppType);
		tradProdInst.setTradProdType(prodType); 
		tradProdInst.setProdInstCode(prodInstCode);
		tradProdInst.setInstant(instant);
		tradProdInst.setMaxDelayDay(maxDelayDay);
		tradProdInst.setMinDelayDay(minDelayDay);
		tradProdInst.setMaxDays(maxDays);
		tradProdInst.setMinDays(minDays);
		tradProdInst.setPppUnit(pppUnit);
		tradProdInst.setUnitPp(unitPp);
		//产品新增的时候默认为无效状态
		tradProdInst.setStatus("0");
		tradProdInst.setPoolType(poolType);
		tradProdInst.setPoolRatio(fpoolRatio);
		
		tradProdInst.setAgeLimit(ageLimit);
		tradProdInst.setMinAge(minAge);
		tradProdInst.setMaxAge(maxAge);
		
		tradProdInst.setMaxOccupLevel(maxOccupLevel);
		tradProdInst.setInsuredNoLimit(insuredNoLimit);
		tradProdInst.setMinInsuredNo(minInsuredNo);
		tradProdInst.setAgentType(agentType);
		tradProdInst.setAdjustStr(adjustStr);
		//tradProdInst.setOperTime(new Date());
		//目的得到添加产品编号便与险种配置
		page.setType(productService.saveTradProdInst(tradProdInst));
		
		return page;
	}
	/**
	 * 编辑产品
	 * @param tradProdDesc
	 * @param tradAppType
	 * @param prodInstCode
	 * @param instant
	 * @param maxDelayDay
	 * @param maxDays
	 * @param minDays
	 * @param unitPp
	 * @param status
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/editProduct")
	public @ResponseBody  Page<TradProdInst> editTradProdInst(String tradProdCode,String tradProdDesc,String tradAppType,String prodInstCode,String instant,Long maxDelayDay,Long maxDays,Long minDays,Long unitPp,String status,String prodType,String poolType,String poolRatio,String ageLimit,Integer minAge,Integer maxAge,String maxOccupLevel,String insuredNoLimit,Integer minInsuredNo,Long minDelayDay,String adjustStr,String agentType,String pppUnit) throws Exception{
		Page<TradProdInst> page =new Page<TradProdInst>();
		
		if(StrUtil.isEmpty(prodInstCode)){
			page.setMessage("产品模板代码不能为空");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(tradAppType)){
			page.setMessage("交易系统投保类型不能为空");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(prodType)){
			page.setMessage("产品类型不能为空");
			page.setResult("error");
			return page;
		}

		if(StrUtil.isEmpty(minDelayDay)){
			page.setMessage("最短延时起保天数不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("(0|[1-9][0-9]*)");  
	        Matcher matcher = pattern.matcher(minDelayDay.toString());
	        if(!matcher.matches()){
				page.setMessage("最短延时起保天数必须是不小于0的整数");
				page.setResult("error");
				return page;
	        }
		}
		if(StrUtil.isEmpty(maxDelayDay)){
			page.setMessage("最长延时起保天数不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("(0|[1-9][0-9]*)");  
	        Matcher matcher = pattern.matcher(maxDelayDay.toString());
	        if(!matcher.matches()){
				page.setMessage("最长延时起保天数必须是不小于0的整数");
				page.setResult("error");
				return page;
	        }else{
	        	if(maxDelayDay<minDelayDay){
					page.setMessage("最长延时起保天数不能小于最短延时起保天数");
					page.setResult("error");
					return page;
	        	}
	        }
		}
		
		if(StrUtil.isEmpty(minDays)){
			page.setMessage("最小保险期间不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("[1-9][0-9]*");  
	        Matcher matcher = pattern.matcher(minDays.toString());
	        if(!matcher.matches()){
				page.setMessage("最小保险期间必须是不小于1的整数");
				page.setResult("error");
				return page;
	        }
		}
		if(StrUtil.isEmpty(maxDays)){
			page.setMessage("最大保险期间不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("[1-9][0-9]*");  
	        Matcher matcher = pattern.matcher(maxDays.toString());
	        if(!matcher.matches()){
				page.setMessage("最大保险期间必须是不小于1的整数");
				page.setResult("error");
				return page;
	        }else{
	        	if(maxDays<minDays){
					page.setMessage("最大保险期间不能小于最小保险期间");
					page.setResult("error");
					return page;
	        	}
	        }
		}
		if(StrUtil.isEmpty(pppUnit)){
			page.setMessage("保险期间类型不能为空");
			page.setResult("error");
			return page;
		}
		
		/**
		 * 校验投保年龄限制不能为空，如果选择 ”是“，则必须输入最低、最高年龄，且最低年龄不大于最高年龄
		 * 如果是”否“，不输入最低、最高年龄
		 */
		if(StrUtil.isEmpty(ageLimit)){
			page.setMessage("请选择投保年龄限制");
			page.setResult("error");
			return page;
		}else{
			if("Y".equals(ageLimit)){
				if(null==minAge){
					page.setMessage("请输入最低投保年龄");
					page.setResult("error");
					return page;
				}else{
			        if(minAge>999||minAge<0){
						page.setMessage("最低年龄为0-999的有效整数");
						page.setResult("error");
						return page;
					}
				}

				if(null==maxAge){
					page.setMessage("请输入最高投保年龄");
					page.setResult("error");
					return page;
				}else{
					if(maxAge>999||maxAge<0){
						page.setMessage("最高年龄为0-999的有效整数");
						page.setResult("error");
						return page;
					}
				}
				
				if(minAge.intValue()>maxAge.intValue()){
					page.setMessage("最低投保年龄不能大于最高投保年龄");
					page.setResult("error");
					return page;
				}
			}
		}
		
		if(StrUtil.isEmpty(instant)){
			page.setMessage("即时投保限制不能为空");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(status)){
			page.setMessage("状态选择错误");
			page.setResult("error");
			return page;
		}else{
			if("0".equals(status)){//无效
				if(productService.isExistProdPlan(tradProdCode)){//存在方案
					page.setMessage("您选择的产品已配置投保方案信息，不允许改为无效");
					page.setResult("error");
					return page;
				}
			}
		}
		
		
		/**
		 * 共保选项 && 共保份额 逻辑：
		 * 1、共保选项为“ 不共保”，产品和其配置的险种均清空共保份额
		 * 2、共保选项为“保单级共保”时，产品的共保份额必填！产品的险种没有共保份额；
		 * 3、共保选项为“险种级共保“是，需要清空产品的 共保份额，如果配置了险种，则险种的共保份额必填！
		 */
		BigDecimal fpoolRatio=null;
		if(StrUtil.isEmpty(poolType)){
			page.setMessage("共保选项不能为空");
			page.setResult("error");
			return page;
		}else{
			if("1".equals(poolType)){
				if(StrUtil.isEmpty(poolRatio)){
					page.setMessage("共保份额不能为空");
					page.setResult("error");
					return page;
				}else{
					Pattern pattern = Pattern.compile("[1-9][0-9]?|100");  
			        Matcher matcher = pattern.matcher(poolRatio.toString());
			        if(!matcher.matches()){
						page.setMessage("共保份额必须是1-100的有效整数");
						page.setResult("error");
						return page;
			        }
				}
					DecimalFormat df = new DecimalFormat("#.00");
					Double ratio = Double.parseDouble(poolRatio);
					if("0".equals(poolRatio)){
						fpoolRatio=new BigDecimal(df.format(Double.parseDouble("0")));
					}else{
						Double ratioPercent = ratio/100;
						fpoolRatio=new BigDecimal(df.format(ratioPercent));
					}
					
					
					//清空该产品下所有险种的共保份额
					TradProdPlan pp = new TradProdPlan();
					pp.setTradProdCode(tradProdCode);
					List<TradProdPlan> list = productService.queryTradProdPlanList(pp);
					if(list.size()>0){
						for(int i=0;i<list.size();i++){
							TradPlanBase temp = new TradPlanBase();
							String tradPlanCode = list.get(i).getTradPlanCode();
							TradPlanBase base = new TradPlanBase();
							base = productService.queryTradPlanBaseByCode(tradPlanCode);
							
							TradPlanBase base2 = new TradPlanBase();
							base2.setTradPlanCode(base.getTradPlanCode());
								
							productService.updatePlanBaseRatio(base2);
						}
					}
				//清空产品的共保份额	
				}else if("2".equals(poolType)){
					TradProdInst tradProdInst = new TradProdInst();
					tradProdInst.setTradProdCode(tradProdCode);
					productService.updateTradProdInst(tradProdInst);
				//清空产品、险种的共保份额
				}else{
					//产品
					TradProdInst tradProdInst = new TradProdInst();
					tradProdInst.setTradProdCode(tradProdCode);
					productService.updateTradProdInst(tradProdInst);

					//清空该产品下所有险种的共保份额
					TradProdPlan pp = new TradProdPlan();
					pp.setTradProdCode(tradProdCode);
					List<TradProdPlan> list = productService.queryTradProdPlanList(pp);
					if(list.size()>0){
						for(int i=0;i<list.size();i++){
							TradPlanBase temp = new TradPlanBase();
							String tradPlanCode = list.get(i).getTradPlanCode();
							TradPlanBase base = new TradPlanBase();
							base = productService.queryTradPlanBaseByCode(tradPlanCode);
							
							TradPlanBase base2 = new TradPlanBase();
							base2.setTradPlanCode(base.getTradPlanCode());
								
							productService.updatePlanBaseRatio(base2);
						}
					}
							
				}
		}
		
		
		//判断类型
		TradProdInst tradProdInst=new TradProdInst();
		tradProdInst.setTradProdCode(tradProdCode);
		//编辑产品时判断产品状态
		if("1".equals(status)){
			List<TradPlanCov> TradPlanCovs =  productService.findState(tradProdInst);
			if(TradPlanCovs.size()==0){
				page.setResult("other");
				
				return page;
			}
		}
		
		/**
		 * 校验最低投保人数限制不能为空，如果选择 ”是“，则必须最低投保人数
		 * 如果是”否“，不输入最低投保人数
		 */
		if(StrUtil.isEmpty(insuredNoLimit)){
			page.setMessage("请选择最低投保人数限制");
			page.setResult("error");
			return page;
		}else{
			if("Y".equals(insuredNoLimit)){
				if(null==minInsuredNo){
					page.setMessage("请输入最低投保人数");
					page.setResult("error");
					return page;
				}else{
					if(minInsuredNo>99999||minInsuredNo<0){
						page.setMessage("最低投保人数为0-99999的有效整数");
						page.setResult("error");
						return page;
					}
				}
			}
		}
		if(StrUtil.isEmpty(unitPp)){
			page.setMessage("最大份数不能为空");
			page.setResult("error");
			return page;
		}else{
			Pattern pattern = Pattern.compile("(0|[1-9][0-9]*)");  
	        Matcher matcher = pattern.matcher(unitPp.toString());
	        if(!matcher.matches()){
				page.setMessage("最大份数必须是不小于0的整数");
				page.setResult("error");
				return page;
	        }
		}
		/**
		 * 销售类型
		 */
		if(StrUtil.isEmpty(agentType)){
			page.setMessage("请选择销售类型");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(tradProdDesc)){
			page.setMessage("交易系统产品描述不能为空");
			page.setResult("error");
			return page;
		}
		tradProdInst.setTradProdDesc(tradProdDesc);
		tradProdInst.setTradAppType(tradAppType);
		tradProdInst.setTradProdType(prodType);
		tradProdInst.setProdInstCode(prodInstCode);
		tradProdInst.setInstant(instant);
		tradProdInst.setMaxDelayDay(maxDelayDay);
		tradProdInst.setMinDelayDay(minDelayDay);
		tradProdInst.setMaxDays(maxDays);
		tradProdInst.setMinDays(minDays);
		tradProdInst.setPppUnit(pppUnit);
		tradProdInst.setUnitPp(unitPp);
		tradProdInst.setStatus(status);
		tradProdInst.setPoolType(poolType);
		tradProdInst.setPoolRatio(fpoolRatio);
		tradProdInst.setAgeLimit(ageLimit);
		tradProdInst.setMinAge(minAge);
		tradProdInst.setMaxAge(maxAge);
		
		tradProdInst.setMaxOccupLevel(maxOccupLevel);
		tradProdInst.setInsuredNoLimit(insuredNoLimit);
		tradProdInst.setMinInsuredNo(minInsuredNo);
		tradProdInst.setAdjustStr(adjustStr);
		tradProdInst.setAgentType(agentType);
		tradProdInst.setOperTime(new Date());
		page.setType(productService.editTradProdInst(tradProdInst));
		
		return page;
	}
	/**
	 * 加载险种模板
	 * @param size
	 * @param current
	 * @param prodNme
	 * @param instCode
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/loadProdPlan")
	public @ResponseBody Page<CoreProdPlan> loadProdPlan(Integer size,Integer current,String tradProdCode) throws SQLException{
		//验证产品代码是否可用TradProdInst
		TradProdInst tradProdInst= productService.queryTradProdInstById(tradProdCode);
		//险种模板表
		Page<CoreProdPlan> page=new Page<CoreProdPlan>();
		page.setCurrent(current);
		page.setSize(size);
		Page<CoreProdPlan> page2=productService.queryProdPlan(page,tradProdInst);
		
		return page2;
	}
	
	/**
	 * 加载已添加的险种
	 * @param size
	 * @param current
	 * @param prodNme
	 * @param instCode
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/loadPlan")
	public @ResponseBody Page<TradPlanBase> loadPlan(Integer size,Integer current,String tradProdCode) throws SQLException{
		//验证产品代码是否可用TradProdInst
		Page<TradPlanBase> page=new Page<TradPlanBase>();
		page.setCurrent(current);
		page.setSize(size);
		Page<TradPlanBase> rpage=productService.queryTradPlanBasePage(page,tradProdCode);
		
		return rpage;
	}
	/**
	 * 保存险种
	 * @param tradProdCode
	 * @param prodInstCode
	 * @param insType
	 * @param planCode
	 * @param instCode
	 * @param insnme
	 * @param tradPlanDesc
	 * @param Amount
	 * @param required
	 * @param calDefId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/savePlan")
	public @ResponseBody Page<CoreProdPlan> savePlan(String tradProdCode,String prodInstCode,String insType,String planCode,String instCode,String insnme,String tradPlanDesc,String Amount,String required,String calDefId,String poolRatio,String calId,String isHealthFlag,HttpSession session) throws Exception{
		Page<CoreProdPlan> page=new Page<CoreProdPlan>();
		
		if(StrUtil.isEmpty(planCode)){
			page.setMessage("请选择险种模板");
			page.setResult("error");
			return page;
		}
		if(StrUtil.isEmpty(tradPlanDesc)){
			page.setMessage("险种名称不能为空");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(calDefId)){
			page.setMessage("算法不能为空");
			page.setResult("error");
			return page;
		}
		
		if(StrUtil.isEmpty(tradProdCode)){
			page.setMessage("产品版本号不能为空");
			page.setResult("error");
			return page;
		}
		

		BigDecimal fAmount=null;	//险种保额
		
		/**
		 *添加险种关于保额逻辑：
		 * 一、如果是“特殊公式算法”，页面将不会传入保额，后台也不做校验，即不保存该字段。
		 * 二、如果不是“特殊公式算法”，接着判断是否为“固定保费算法”：
		 * 1、非”固定保费算法“，前台后台做同样校验：必填 和 输入保额的合法类型
		 * 2、”固定保费算法“，前后台做同样校验：只有输入的保额非空时，才去校验保额内容是否合法，没有输入则不校验不保存
		 * 
		 */
		if(!"0000000005".equals(calDefId)&&!"0000000006".equals(calDefId)&&!"0000000007".equals(calDefId)){
			if(!"0000000002".equals(calDefId)){
				if(StrUtil.isEmpty(Amount)){
					page.setMessage("险种保额不能为空");
					page.setResult("error");
					return page;
				}
				try{
					DecimalFormat df = new DecimalFormat("#.00");
					fAmount=new BigDecimal(df.format(Double.parseDouble(Amount)));
				}catch(Exception e){
					page.setMessage("输入金额不合法");
					page.setResult("error");
					logger.info("输入金额不合法",e);
					return page;
				}
				
				Pattern pnum=Pattern.compile("^(([1-9]\\d{0,9})|0)(\\.\\d{1,2})?$"); 
				if(!pnum.matcher(Amount).matches()) {
					page.setMessage("输入金额不合法");
					page.setResult("error");
					return page;
				}
				//没有小数，判断输入金额长度不能超过8位 （8位是由数据库对该字段的类型长度限制最大位，超出8位将报错）
				if(-1==Amount.indexOf(".")){
					if(Amount.length()>8){
						page.setMessage("输入金额长度不能超过8位数字");
						page.setResult("error");
						return page;
					}
				}
			}else{
				if(StrUtil.isNotEmpty(Amount)){
					try{
						DecimalFormat df = new DecimalFormat("#.00");
						fAmount=new BigDecimal(df.format(Double.parseDouble(Amount)));
					}catch(Exception e){
						page.setMessage("输入金额不合法");
						page.setResult("error");
						logger.info("输入金额不合法",e);
						return page;
					}
					
					Pattern pnum=Pattern.compile("^(([1-9]\\d{0,9})|0)(\\.\\d{1,2})?$"); 
					if(!pnum.matcher(Amount).matches()) {
						page.setMessage("输入金额不合法");
						page.setResult("error");
						return page;
					}
					//没有小数，判断输入金额长度不能超过8位 （8位是由数据库对该字段的类型长度限制最大位，超出8位将报错）
					if(-1==Amount.indexOf(".")){
						if(Amount.length()>8){
							page.setMessage("输入金额长度不能超过8位数字");
							page.setResult("error");
							return page;
						}
					}
				}
			}
		}else{
			if(StrUtil.isNotEmpty(Amount)){
				try{
					DecimalFormat df = new DecimalFormat("#.00");
					fAmount=new BigDecimal(df.format(Double.parseDouble(Amount)));
				}catch(Exception e){
					page.setMessage("输入金额不合法");
					page.setResult("error");
					logger.info("输入金额不合法",e);
					return page;
				}
				
				Pattern pnum=Pattern.compile("^(([1-9]\\d{0,9})|0)(\\.\\d{1,2})?$"); 
				if(!pnum.matcher(Amount).matches()) {
					page.setMessage("输入金额不合法");
					page.setResult("error");
					return page;
				}
				//没有小数，判断输入金额长度不能超过8位 （8位是由数据库对该字段的类型长度限制最大位，超出8位将报错）
				if(-1==Amount.indexOf(".")){
					if(Amount.length()>8){
						page.setMessage("输入金额长度不能超过8位数字");
						page.setResult("error");
						return page;
					}
				}
			}
		}
		
		//判断产品的共保选项是否”险种级共保“，是则要求填写产品的”共保份额“，否则不填写
		BigDecimal fpoolRatio=null;	//共保份额
		TradProdInst prod = productService.queryTradProdInstById(tradProdCode);
		if("2".equals(prod.getPoolType())){
			if(StrUtil.isEmpty(poolRatio)){
				page.setMessage("共保份额不能为空");
				page.setResult("error");
				return page;
			}else{
				Pattern pattern = Pattern.compile("[1-9][0-9]?|100");  
				Matcher matcher = pattern.matcher(poolRatio.toString());
				if(!matcher.matches()){
					page.setMessage("共保份额必须是1-100的有效整数");
					page.setResult("error");
					return page;
				}
			}
			DecimalFormat df = new DecimalFormat("#.00");
			Double ratio = Double.parseDouble(poolRatio);
			if("0".equals(poolRatio)){
				fpoolRatio=new BigDecimal(df.format(Double.parseDouble("0")));
			}else{
				Double ratioPercent = ratio/100;
				fpoolRatio=new BigDecimal(df.format(ratioPercent));
			}
		}
		
		//判断险种是否已经添加
		CoreProdPlan choosePlanTemplet=null;//gatewayProductService.queryCoreProdPlan(planCode);
		GatewayUser user = (GatewayUser)session.getAttribute(Constants.SESSION_USER);
		productService.savePlan(choosePlanTemplet,tradProdCode,prodInstCode,insType,planCode,instCode,insnme,tradPlanDesc,fAmount,required,calDefId,fpoolRatio,calId,isHealthFlag,user.getUserCode());
		
		page.setMessage("保存成功");

		return page;
	}
	/**
	 * 编辑险种
	 * @param tradPlanDesc
	 * @param ecalDefId
	 * @param Amount
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/editPlan")
	public @ResponseBody Page<CoreProdPlan> editPlan(String tradPlanCode,String tradPlanDesc,String calDefId,String Amount,String poolRatio,String calId) throws Exception{
		Page<CoreProdPlan> page=new Page<CoreProdPlan>();
		
		if(StrUtil.isEmpty(tradPlanCode)){
			page.setMessage("险种代码不能为空");
			page.setResult("error");
			return page;
		}
		if(StrUtil.isEmpty(tradPlanDesc)){
			page.setMessage("险种名称不能为空");
			page.setResult("error");
			return page;
		}

		if(StrUtil.isEmpty(calDefId)){
			page.setMessage("算法不能为空");
			page.setResult("error");
			return page;
		}
		
		BigDecimal fAmount=null;

		if(!"0000000005".equals(calDefId)&&!"0000000006".equals(calDefId)&&!"0000000007".equals(calDefId)){
			if(!"0000000002".equals(calDefId)){
				if(StrUtil.isEmpty(Amount)){
					page.setMessage("输入金额不能为空");
					page.setResult("error");
					return page;
				}
				
				try{
					DecimalFormat df = new DecimalFormat("#.00");
					fAmount=new BigDecimal(df.format(Double.parseDouble(Amount)));
				}catch(Exception e){
					page.setMessage("输入金额不合法");
					page.setResult("error");
					logger.info("输入金额不合法",e);
					return page;
				}
				
				Pattern pnum=Pattern.compile("^(([1-9]\\d{0,9})|0)(\\.\\d{1,2})?$"); 
				if(!pnum.matcher(Amount).matches()) {
					page.setMessage("输入金额不合法");
					page.setResult("error");
					return page;
				}
				//没有小数，判断输入金额长度不能超过8位 （8位是由数据库对该字段的类型长度限制最大位，超出8位将报错）
				if(-1==Amount.indexOf(".")){
					if(Amount.length()>8){
						page.setMessage("输入金额长度不能超过8位数字");
						page.setResult("error");
						return page;
					}
				}
			}else{
				if(StrUtil.isNotEmpty(Amount)){
					try{
						DecimalFormat df = new DecimalFormat("#.00");
						fAmount=new BigDecimal(df.format(Double.parseDouble(Amount)));
					}catch(Exception e){
						page.setMessage("输入金额不合法");
						page.setResult("error");
						logger.info("输入金额不合法",e);
						return page;
					}
					
					Pattern pnum=Pattern.compile("^(([1-9]\\d{0,9})|0)(\\.\\d{1,2})?$"); 
					if(!pnum.matcher(Amount).matches()) {
						page.setMessage("输入金额不合法");
						page.setResult("error");
						return page;
					}
					//没有小数，判断输入金额长度不能超过8位 （8位是由数据库对该字段的类型长度限制最大位，超出8位将报错）
					if(-1==Amount.indexOf(".")){
						if(Amount.length()>8){
							page.setMessage("输入金额长度不能超过8位数字");
							page.setResult("error");
							return page;
						}
					}
				}
			}
		}else{
			if(StrUtil.isNotEmpty(Amount)){
				try{
					DecimalFormat df = new DecimalFormat("#.00");
					fAmount=new BigDecimal(df.format(Double.parseDouble(Amount)));
				}catch(Exception e){
					page.setMessage("输入金额不合法");
					page.setResult("error");
					logger.info("输入金额不合法",e);
					return page;
				}
				
				Pattern pnum=Pattern.compile("^(([1-9]\\d{0,9})|0)(\\.\\d{1,2})?$"); 
				if(!pnum.matcher(Amount).matches()) {
					page.setMessage("输入金额不合法");
					page.setResult("error");
					return page;
				}
				//没有小数，判断输入金额长度不能超过8位 （8位是由数据库对该字段的类型长度限制最大位，超出8位将报错）
				if(-1==Amount.indexOf(".")){
					if(Amount.length()>8){
						page.setMessage("输入金额长度不能超过8位数字");
						page.setResult("error");
						return page;
					}
				}
			}
		}
		
		//根据险种代码，查询所对应的产品代码
		TradProdPlan pp = new TradProdPlan();
		pp.setTradPlanCode(tradPlanCode);
		TradProdPlan prodplan = productService.getTradProdPlan(pp);
		
		//根据产品代码，获取该产品的 共保选项——poolType的值
		TradProdInst inst = new TradProdInst();
		TradProdInst prod = productService.queryTradProdInstById(prodplan.getTradProdCode());

		BigDecimal fpoolRatio=null;
		if("2".equals(prod.getPoolType())){
				if(StrUtil.isEmpty(poolRatio)){
					page.setMessage("共保份额不能为空");
					page.setResult("error");
					return page;
				}else{
					Pattern pattern = Pattern.compile("[1-9][0-9]?|100");  
			        Matcher matcher = pattern.matcher(poolRatio.toString());
			        if(!matcher.matches()){
						page.setMessage("共保份额必须是1-100的有效整数");
						page.setResult("error");
						return page;
			        }
				}
					DecimalFormat dfm = new DecimalFormat("#.00");
					Double ratio = Double.parseDouble(poolRatio);
					if("0".equals(poolRatio)){
						fpoolRatio=new BigDecimal(dfm.format(Double.parseDouble("0")));
					}else{
						Double ratioPercent = ratio/100;
						fpoolRatio=new BigDecimal(dfm.format(ratioPercent));
					}
		}
		//交易系统险种表
		TradPlanBase tradplanbase=new TradPlanBase();
		tradplanbase.setTradPlanCode(tradPlanCode);
		tradplanbase.setTradPlanDesc(tradPlanDesc);
		tradplanbase.setPoolRatio(fpoolRatio);
		
		TradPlanCov tradPlanCov=new TradPlanCov();
		tradPlanCov.setTradPlanCode(tradPlanCode);
		List<TradPlanCov> tradPlanCovs=productService.queryTradPlanCovList(tradPlanCov);
	
		//判断责任金额之和是否大于保额
		tradplanbase.setAmount(fAmount);
		//tradplanbase = productService.queryTradPlanBase(tradplanbase);
		
		//判断险种是否已经添加
		//算法表
		RiskAlgMap riskAlgMap=new RiskAlgMap();
		riskAlgMap.setTradPlanCode(tradPlanCode);
		riskAlgMap.setCalDefId(calDefId);
		riskAlgMap.setCalId(calId);
		productService.editTradPlanBase(tradplanbase,riskAlgMap);
		page.setMessage("修改成功");
		return page;
	}
	/**
	 * 加载责任
	 * @param size
	 * @param current
	 * @param tradPlanCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/coverage")
	public @ResponseBody Page<TradPlanCov> coverage(Integer size,Integer current,String tradPlanCode,String covCode,String instCode) throws Exception{
		Page<TradPlanCov> page=new Page<TradPlanCov>();
		page.setCurrent(current);
		page.setSize(size);
		//交易系统责任表
		TradPlanCov tradPlanCov=new TradPlanCov();
		tradPlanCov.setTradPlanCode(tradPlanCode);
		tradPlanCov.setTradCovCode(covCode);
		tradPlanCov.setInstCode(instCode);
		
		page.setType(tradPlanCov);
		Page<TradPlanCov> page2=productService.queryCoveragePage(page);
		return page2;
	}

	/**
	 * 保存责任
	 * @param planCovs
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/saveCoverage")
	public @ResponseBody Page<TradPlanCov> saveCoverage(@RequestBody List<TradPlanCov> planCovs) throws Exception{
		Page<TradPlanCov> page=new Page<TradPlanCov>();
		if(null==planCovs||planCovs.size()<=0){
			page.setMessage("无法保存，后台没有参数传入");
			page.setResult("error");
			return page;
		}

		//如果所有责任保额均为空，则提示用户至少输入一个保额
/*		int num = 0;
		for(int i=0;i<planCovs.size();i++){
			if(null == planCovs.get(i).getCovAmt()){
				num = num+0;
			}else{
				num = num+1;	
			}
		}
		if(num==0){
			page.setMessage("请至少输入一个责任保额");
			page.setResult("error");
			return page;
		}
	*/	
		TradPlanBase planbase = productService.queryTradPlanBaseByCode(planCovs.get(0).getTradPlanCode().toString());
		BigDecimal planbaseAmount = planbase.getAmount();
		
		BigDecimal countbigDecimal=new BigDecimal(0);
		for(int i=0;i<planCovs.size();i++){
				if(StrUtil.isEmpty(planCovs.get(i).getTradPlanCode().toString())){
					page.setMessage("交易系统险种代码不能为空");
					page.setResult("error");
				}
				
				if(null != planCovs.get(i).getCovAmt())
				{
					if(new BigDecimal(0).compareTo(planCovs.get(i).getCovAmt())==1){
						page.setMessage("输入金额不合法");
						page.setResult("error");
						return page;
					}
				
					int result =planbaseAmount.compareTo(planCovs.get(i).getCovAmt()); 
					if(-1==result){
						page.setMessage("输入责任保额不能大于险种保额");
						page.setResult("error");
						return page;
					}
				}
		}
		String tradPlanCode=planCovs.get(0).getTradPlanCode().toString();
		TradPlanBase tradPlanBase=new TradPlanBase();
		tradPlanBase.setTradPlanCode(tradPlanCode);
		tradPlanBase=productService.queryTradPlanBase(tradPlanBase);
		if(null==tradPlanBase){
			page.setMessage("错误提交");
			page.setResult("error");
			return page;
		}
		
		//修改交易系统责任名称
		for(int i=0;i<planCovs.size();i++){
			String trad_Cov_Code=planCovs.get(i).getTrad_Cov_Code();
			String trad_Cov_Name=planCovs.get(i).getTradCovName();
			String[] cid=trad_Cov_Code.split(";",-1);
			String[] cname=trad_Cov_Name.split(";",-1);
			for(int j=0;j<cid.length;j++){
				TradCov tradCov=new TradCov();
				tradCov.setTradCovCode(cid[j]);
				tradCov.setTradCovName(cname[j]);
				GatewayTradCovDao.update(tradCov);
			}
		}
		
		//验证 产品有效状态是否能修改责任保费
		productService.saveCov(planCovs);
		page.setMessage("修改成功");
		return page;
	}
	/**
	 * 删除产品
	 * @param tradProdCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/delete")
	public @ResponseBody Page<TradProdInst> deleteTradProdInst(String tradProdCode) throws Exception{
		Page<TradProdInst> page=new Page<TradProdInst>();
		if(StrUtil.isEmpty(tradProdCode)){
			page.setMessage("操作错误");
			page.setResult("error");
		}
		//交易系统产品表
		TradProdInst tradProdInst=new TradProdInst();
		tradProdInst.setTradProdCode(tradProdCode);
		tradProdInst=productService.queryTradProdInst(tradProdInst);
		
		if(null!=tradProdInst&&StrUtil.isNotEmpty(tradProdInst.getStatus())){
			if("0".equals(tradProdInst.getStatus())){
				List<TradInsuPlan> list = productService.queryTradInsuPlans(tradProdInst);
				if(list!=null&&!list.isEmpty()){
					page.setMessage("您选择的产品已配置投保方案信息，不允许删除");
					page.setResult("error");
					return page;
				}
				productService.deleteTradProdInst(tradProdInst);
				page.setMessage("删除成功");
				return page;
			}else {
				page.setMessage("您选择的产品当前为有效状态,暂不能删除");
				page.setResult("error");
				return page;
			}
		}
		page.setMessage("操作错误");
		page.setResult("error");
		return page;
	}
	/**
	 * 删除险种
	 * @param tradPlanCode
	 * @param tradProdCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/deletePlan")
	public @ResponseBody Page<TradPlanCov> deletePlan(String tradPlanCode,String tradProdCode,String isHealthFlag) throws Exception{
		Page<TradPlanCov> page=new Page<TradPlanCov>();
		
		
		if(StrUtil.isEmpty(tradPlanCode)||StrUtil.isEmpty(tradProdCode)){
			page.setMessage("操作异常");
			page.setResult("error");
			return page;
		}
		TradProdPlan tradProdPlan=new TradProdPlan();
		tradProdPlan.setTradProdCode(tradProdCode);
		tradProdPlan.setTradPlanCode(tradPlanCode);
		//交易系统险种表
		TradPlanBase tradPlanBase=new TradPlanBase();
		tradPlanBase.setTradPlanCode(tradPlanCode);
		//交易系统责任表
		TradPlanCov tradPlanCov=new TradPlanCov();
		tradPlanCov.setTradPlanCode(tradPlanCode);
		//算法表
		RiskAlgMap riskAlgMap=new RiskAlgMap();
		riskAlgMap.setTradPlanCode(tradPlanCode);
		
		productService.deletePlan(tradProdPlan,tradPlanBase,tradPlanCov,riskAlgMap,isHealthFlag);
		page.setMessage("险种删除成功");
		return page;
	}
	
	
	/**
	 * 查询产品类型
	 * @return
	 */
	@RequestMapping(value = "/queryProdType")
	public @ResponseBody List<DictDto> getProdTypes(String parentCode){
		List<DictDto> prodTypeList = DictCache.getProdType(parentCode);
		return prodTypeList;
	}

	
	/**
	 * 查询共保选项
	 * @return
	 */
	@RequestMapping(value = "/queryPoolType")
	public @ResponseBody List<DictDto> getpolPoolTypes(){
		List<DictDto> polPoolType = DictCache.getDict(Constants.DICT_POL_POOL_TYPE);
		return polPoolType;
	}
	/**
	 * 查询折扣系数选项
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "/getDiscountType")
	public @ResponseBody List<Map>  getDiscountType() throws Exception{
		List<Map> discountType = this.productService.getDiscountTypes();
		return discountType;
	}
	
	/**
	 * 查询子险种算法
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "/getChildCal")
	public @ResponseBody List<TradItemCal>  getChildCal(String calDef) throws Exception{
		TradItemCal trad=new TradItemCal();
		trad.setCalDefId(calDef);
		trad.setTargetField("prem");
		List<TradItemCal> tradCalDef=productService.getgetChildCals(trad);
		return tradCalDef;
	}
	
	
	/**
	 * 查询保险期间
	 * @return
	 */
	@RequestMapping(value = "/queryInsurePeriod")
	public @ResponseBody List<DictDto> queryInsurePeriod(){
		List<DictDto> insurePeriodList = DictCache.getDict(Constants.DICT_INSURE_PERIOD);
		return insurePeriodList;
	}

}
